<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"> 
  <title>发布房源</title>
  <script src="js/jquery.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
  
<script src="js/moment-with-locales.min.js"></script>
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="city.js"></script>     
<style type="text/css">
    header{
      height: 65px;
      background: rgba(247,235,175,1);
    }
    header span{
      line-height: 65px;
      font-size:22px;
      font-weight: bolder;
      float: left;
      margin-left: 50px;
    }
    header #login{
      display: inline-block;
      float: right;
      margin-right: 150px;
      margin-top: 15px;
    }
        body {
            height: 670px;
            background: url(image/7.jpg) no-repeat;
            background-size: 100% 100%;
            text-align: center;
        }

  input,select, textarea,.input-group{
    height: 25px;
      border: 0;
      border-radius: 3px;
      margin-bottom: 15px;
  }
  .publishHotel{
    margin-left: 200px;
    margin-top: 30px;
    width: 900px;
    height: 550px;
    /* background: rgba(255,255,203,0.8); */
  }
  .data-common{
    display: inline-block;
    width: 400px;
    /* margin-top: 20px; */
  }
  .common-span{
    display: inline-block;
    width: 100px;
    text-align: right;
  }
  .common-input{
    width: 200px;
    display: inline-block;
  }
  .sideBar{
    width: 200px;
    height: 550px;
    /* display: inline-block; */
    float: left;
    background: rgba(255,255,208,0.8);
    border-right:1px solid rgba(255,255,208,1);
  }
  .data-common1{
    width: 800px;
  }
  .common-textarea{
    vertical-align: text-top;
    width: 505px;
    display: inline-block;
  }

  </style>
</head>
<body>
  <header>
    <span align="left">分享式民宿酒店预订系统——房源发布</span>
 
  </header>
  <div class="sideBar">
          <div class="row" style="width: 215px;">
            <div class="span2">
              <ul class="nav nav-pills nav-stacked">
                <li class="active">
                  <a href="#">发布房源</a></li>   
                <li><a href="publishhistory.html">我的房源</a></li>
                <li><a href="viewpersoninformation.html">个人中心</a></li> 
                <li><a href="index.html" id="over">注销登录</a></li>
              </ul>
            </div>
          </div>
  </div>
  <div class="publishHotel">
    <div>
        <div class="data-common">
            <span class="common-span">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格：</span>
            <input class="common-input form-control" type="text" value="" id="price" name="price">
        </div>
        <div class="data-common" >
            <span class="common-span">房源类型：</span>
            <select class="common-input form-control" id="housingType" name="housingType">
              <option value="无">请选择房源类型</option>
              <option value="个人公寓" class="s">个人公寓</option>
              <option value="酒店公寓" class="s">酒店公寓</option>
            </select>
        </div>
    </div>
    <div>
        <div class="data-common">
            <span class="common-span">所属省份：</span>
            <select class="common-input form-control" id="province"></select>
        </div>
        <div class="data-common" >
            <span class="common-span">所属城市：</span>
            <select class="common-input form-control" id="city"></select>
        </div>
    </div>
    <div>
        <div class="data-common1">
           <span class="common-span">具体地址：</span>
           <textarea rows="2" class="form-control common-textarea" type="text" value="" id="address" name="address"></textarea>
        </div>
    </div>
    <div>
        <div class="data-common">
            <span class="common-span">房间类型：</span>
            <select class="common-input form-control" id="roomType" name="roomType">
                  <option value="无">请选择房间类型</option>
                  <option value="一室一卫" class="s">一室一卫</option>
                  <option value="一室一厅" class="s">一室一厅</option>
                  <option value="两室一厅" class="s">两室一厅</option>
                  <option value="三室一厅" class="s">三室一厅</option>
                  <option value="三室两厅" class="s">三室两厅</option>
                </select>
        </div>
        <div class="data-common" >
             <span class="common-span">可住人数：</span>
             <input class="common-input form-control" type="text" value="" id="canLiveInNumber" name="canLiveInNumber">
        </div>
  </div>  
  <div>
 <div>
        <div class="data-common" style="padding:0 50px;">
            <span class="common-span">开始时间：</span>
            <div class="input-group" style="width: 200px; float: right;" >  
                <input type="text" class="form-control date " id='availableStartTime'>  
                <span class="input-group-addon">  
                    <i class="glyphicon glyphicon-calendar"></i>  
                </span>
            </div>
        </div>
        <div class="data-common" style="padding:0 50px;">
            <span class="common-span" for="">结束时间：</span> 
            <div class="input-group" style="width: 200px;float: right;" >  
                <input type="text" class="form-control date" id='availableEndTime'>  
                <span class="input-group-addon">  
                    <i class="glyphicon glyphicon-calendar"></i>  
                </span>
            </div>
             <!-- <span class="common-span">截至时间：</span>
             <input class="common-input form-control" type="date" value="2019-09-24"/> -->
        </div>
    </div>        
    </div>
    <div>
        <div class="data-common1">
           <span class="common-span">房屋介绍：</span>
           <textarea rows="2" class="form-control common-textarea" type="text" value="" id="introduce" name="introduce"></textarea>
        </div>
    </div>
    <div>
        <div class="data-common1">
           <span class="common-span">入住须知：</span>
           <textarea rows="2" class="form-control common-textarea" type="text" value="" id="notice" name="notice"></textarea>
        </div>
    </div>
 <div>
                <button class="btn btn-success btn-xm" type="button" id="publish">发布房源</button>
              </div>


    </div>
  </div>
</div>
  </div>
  <script>
    (function(){
        // console.log(localStorage.getItem('userId'))
        var userId = localStorage.getItem('userId')//获取用户Id
        console.log(userId)
        if(!userId){
            window.location.href='index.html'
            //无用户id（级无登陆直接近页面不可以，直接去登录）
        }else{
            console.log(222,userId)
        }
      $('.date').datetimepicker({  
          format: 'YYYY-MM-DD',  
          locale: moment.locale('zh-cn')  
        }); 
      $("#publish").click(function(){

        var price = $("#price").val();
        
        var province = $("#province").val();
        var city = $("#city").val();
        var address = $("#address").val();
        var housingType = $("#housingType").val();
        var roomType = $("#roomType").val();
        var canLiveInNumber = $("#canLiveInNumber").val();
        var availableStartTime = $("#availableStartTime").val();
        var availableEndTime = $("#availableEndTime").val();
        var introduce = $("#introduce").val();
        var notice = $("#notice").val();

        $.get('http://localhost:8080/housing/add',{
          userKeyId: userId,
          price: price,
          housingType: housingType,
          province: province,
          city: city,
          address: address,
          roomType: roomType,
          canLiveInNumber: canLiveInNumber,
          availableStartTime: availableStartTime,
          availableEndTime: availableEndTime,
          introduce: introduce,
          notice: notice
        },function(data){
          if(data.code == 1){
            alert("成功")
          }else{
            alert(data.data)
          }
          console.log(data)
      })

      })

        var pHtmlStr = '';  
        for(var name in pc){  
            pHtmlStr = pHtmlStr + '<option>'+name+'</option>';  
        }  
        $("#province").html(pHtmlStr);  
        $("#province").change(function(){  
            var pname = $("#province option:selected").text();  
            var pHtmlStr = '';  
            var cityList = pc[pname];  
            for(var index in cityList){  
                pHtmlStr = pHtmlStr + '<option>'+cityList[index]+'</option>';  
            }  
            $("#city").html(pHtmlStr);  
        });  
        $("#province").change();
        // 注销事件
        $("#over").click(function(){
            localStorage.setItem('userId', '')
        });
       })();  
     </script>
</body>
</html>